$(function () {
    $('.editad').on('click', function () {
        var _this = $(this);
        var _id = '{' + _this.attr('data') + '}';
        var _data = eval('(' + _id + ')');
        layer.open({
            type: 1, //0-4的选择,
            title: [
                '编辑广告',
                'border:none; background:#61BA7A; color:#fff;'
            ],
            border: [0],
            fix: false,
            shadeClose: true,
            bgcolor: '#eee', //设置层背景色
            area: ['488px', 'auto'],
            content: '<div style="padding:50px;"><form name="form1" action="#" method="post"><input type="hidden" name="posid" value="' + _data.posid + '"><input type="hidden" name="type" value="' + _data.type + '"><input type="hidden" name="theme_id" value="' + _data.theme_id + '"><table class="table">\n\
<tr><td width="60">文字</td><td colspan="3"><input name="title"type="text"id="title"size="30"class="form-control"value="' + _data.title + '"/><input name="id"type="hidden"id="id"size="15"maxlength="20"value="' + _data.id + '"/></td></tr>\n\
<tr><td>项目URL</td><td colspan="3"><input name="gdurl"type="text"id="gdurl"size="30"value="' + _data.gdurl + '"class="form-control"/></td></tr><tr>\n\
<tr><td class="td1">添加图片</td><td colspan="3">\n\
<input type="file"name="pic"id="pic"style="display:none;"onChange="return ajaxFileUpload();"><input readonly name="picpath"id="picpath"class="form-control" value="' + _data.picpath + '"/><input type="button" id="upbtn"value="上传照片"class="btn-default btn" style="margin:5px;"onclick="$(\'#pic\').click()">\n\
<br/><a href="#" id="seepic"title="查看">图片查看</a></td>\n\
<tr><td colspan=4 align=center><input name="submit"type="button"class="btn-default btn"id="submit1"value="提交"></td></tr></table></div>' //此处放了防止html被解析，用了\转义，实际使用时可去掉
            ,
            shift: 'top' //从上动画弹出
        });
        $('#submit1').click(function () {
            $.ajax({
                url: '/back/wap_theme/addEditWapQuestionData/',
                type: 'post',
                data: $('form').serializeArray(),
                async: false, //默认为true 异步
                error: function () {
                    alert('error');
                },
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.status == '1') {
                        layer.alert(obj.message, {icon: 1});
                    } else {
                        layer.alert(obj.message, {icon: 2});
                    }
                }
            });
        });
        return false;
    });

    $(document).on('click', '#seepic', function () {
        var _val = $('#picpath').val();
        if (_val != '') {
            layer.open({
                type: 1,
                title: false, //不显示默认标题栏
                // shadeClose: true,
//                shade: [1], //不显示遮罩
                area: ['auto', 'auto'],
                // page: {html: '<img src="' + _val + '" alt="">'}
                content:'<img style="display:block" src="' + _val + '" alt="">'
            });
        }
        return false;
    });

});
function ajaxFileUpload(){
    $.ajaxFileUpload(
        {
            url: image_upload_url, //你处理上传文件的服务端
            secureuri: false,
            fileElementId: 'pic',
            dataType: 'json',
            success: function (data)
            {
                if (data.status != '0') {
                    $('#picpath').val(data.pic);
                } else {
                    layer.alert(data.message, 8);
                }
            }
        }
    );
    return false;
}
function addcss(obj) {
    var _this = $(obj);
    _this.append('<button class="editdata" title="添加位置">+</button>');
}
function recss(obj) {
    var _this = $(obj);
    _this.children('.editdata').remove();
}
